package com.psfd.demo.controller;


import com.psfd.demo.entity.TypesOfReaders;
import com.psfd.demo.service.ITypesOfReadersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 *  前端控制器
 * </p>
 *读者类型
 * @author 撒旦
 * @since 2020-07-10
 */
@RestController
public class TypesOfReadersController {

    @Autowired
    private ITypesOfReadersService typesOfReadersService;

    //增加
    @RequestMapping("/typesOfReadersinsert")
    public ModelAndView insert(TypesOfReaders typesOfReaders){
        ModelAndView modelAndView = new ModelAndView();
        typesOfReadersService.save(typesOfReaders);
        modelAndView.addObject("typesofreadersList",typesOfReadersService.list());
        modelAndView.setViewName("TypesOfReadersQuery");
        return modelAndView;
    }

    //修改
    @RequestMapping("/typesOfReadersupdate")
    public ModelAndView update(TypesOfReaders typesOfReaders){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("typesOfReaders",typesOfReaders);
        modelAndView.setViewName("TypesOfReadersUpdate");
        return modelAndView;
    }

    //修改
    @RequestMapping("/typesOfReadersupdate1")
    public ModelAndView update1(TypesOfReaders typesOfReaders){
        typesOfReadersService.updateById(typesOfReaders);
        return query();
    }

    //删除
    @RequestMapping("/typesOfReadersdelete")
    public ModelAndView delete(Integer id){
        ModelAndView modelAndView = new ModelAndView();
        typesOfReadersService.removeById(id);
        System.err.println("删除的ID为："+id);
        modelAndView.addObject("typesofreadersList",typesOfReadersService.list());
        modelAndView.setViewName("TypesOfReadersQuery");
        return modelAndView;
    }

    //查询
    @RequestMapping("/typesOfReadersquery")
    public ModelAndView query(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("typesofreadersList",typesOfReadersService.list());
        System.err.println(typesOfReadersService.list());
        modelAndView.setViewName("TypesOfReadersQuery");
        return modelAndView;
    }

}

